Added and completed all of the test functions for data-and-functions …#3
Added and completed all of the test functions for data-and-functions …#3jikehara wants to merge 1 commit intoAmericaCampaign:masterfrom
Conversation
jcheroske
left a comment
There was a problem hiding this comment.
Your code is solid. Most of my comments are style-related. I'm looking forward to seeing your next answers.
| const getActiveUsers = (data) => { | ||
| if (data == null || data.users == null) { | ||
| return null | ||
| } else { |
There was a problem hiding this comment.
You can dump the else block if you want.
| } else { | ||
| const activeUsers = [] | ||
| data.users.forEach((u) => { | ||
| if (u.accountActive === true) { |
There was a problem hiding this comment.
You've already got a boolean. No need to create another one:
if (u.accountActive) {
| return null | ||
| } else { | ||
| const orders = [] | ||
| data.orders.forEach((o) => { |
There was a problem hiding this comment.
Try writing this as a map since you've got the basics down.
| if (data == null || data.products == null || id == null) { | ||
| return null | ||
| } else { | ||
| return data.products.find((p) => { |
There was a problem hiding this comment.
Nice use of find. You can drop the block and use an implicit return if you want. You can also drop the parens around (p) since you only have one param in your lambda.
| throw new Error('Missing data or ID') | ||
| } | ||
| const order = data.orders.find((o) => o.id === id) | ||
| if (order === undefined) { |
There was a problem hiding this comment.
You can totally do the test the way you have it, but you could also just shorten it to:
if (!order) {
| return null | ||
| } | ||
| const productArray = [] | ||
| order.products.forEach((p) => { |
There was a problem hiding this comment.
You could use map here as well.
| @@ -0,0 +1,18 @@ | |||
| import getProductById from './getProductById' | |||
There was a problem hiding this comment.
Try importing getProductsForOrder instead and just use that.
…1 and 2.